<script setup>

// 路径导航
import {reactive, ref} from "vue";
import {RULE} from "../../../const/index.js";
import {ElMessage} from "element-plus";
import router from "../../../router/index.js";
import MyNav from "../../../components/MyNav.vue";
import MyForm from "../../../components/MyForm.vue";
import {insertApi, listApi} from "../../../api/axios.js";


// 路径导航
const navItems = [
  {icon: 'Platform', label: '班级管理', url: '/Direction'},
  {icon: 'Rank', label: '方向列表', url: '/Direction'},
  {icon: 'Plus', label: '添加新方向'},
];

// 表单项 + 表单值 + 表单规则
let items = ref([
  {label: '方向名称', prop: 'title', required: true},
  {label: '方向描述', prop: 'info', type: 'textarea'},
]);
let params = reactive({});
let rules = {title: RULE.TITLE, info: RULE.INFO};

/* ======================================== 添加成功后 ================================================ */

function insertSuccess() {
  ElMessage.success('添加记录成功');
  setTimeout(() => router.push('/Direction'), 1000);
}

</script>

<template>
  <my-nav :items="navItems"/>
  <el-card class="direction-insert-card" header="添加新方向">
    <my-form type="insert"
             :items="items"
             :params="params"
             :rules="rules"
             :api="insertApi"
             :args="{module: 'direction'}"
             :callback="insertSuccess"/>
  </el-card>
</template>

<style scoped lang="scss">
 .direction-insert-card {
   width: 60%; /// 宽度
   margin: 65px auto 0; // 外边距
 }
</style>